const fs = require('fs');
const path = require('path');
const fetch = require('dva').fetch;

async function init() {
  const { data } = await fetch('http://wccg.tech:82/api/wuxi/api/majorProject/getSafeIndex').then(
    resp => {
      return resp.json();
    },
  );

  //   const _data = [...data.projectInfo, ...data.sectionProjectInfo];

  //   _data.forEach(({ projectName, projectId }) => {
  //     createFile(projectName, projectId);
  //   });

  data.sectionProjectInfo.forEach(({ projectName, projectId }) => {
    createFile(projectName, projectId, 14);
  });
  data.projectInfo.forEach(({ projectName, projectId }) => {
    createFile(projectName, projectId, 13);
  });
}

init();

const typesArr = [
  { affix: '_red', fn: getRedImgStr },
  { affix: '_yellow', fn: getYellowImgStr },
  { affix: '', fn: getGreenImgStr },
];

function createFile(name, id, fontSize = 16) {
  typesArr.forEach(({ affix, fn }) => {
    fs.writeFile(
      path.resolve(__dirname, `../public/images/billboard/${id}${affix}.svg`),
      fn(name, fontSize),
      'utf8',
      () => {
        console.log(`文件${name}${id}${affix} 创建成功`);
      },
    );
  });
}

function getRedImgStr(name, fontSize) {
  return `<?xml version="1.0" encoding="UTF-8"?>
  <svg width="240px" height="224px" viewBox="0 0 240 224" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <title>标记</title>
      <defs>
          <linearGradient x1="100%" y1="98.1720976%" x2="0%" y2="98.3278508%" id="linearGradient-1">
              <stop stop-color="#FF3D3D" stop-opacity="0.3" offset="0%"></stop>
              <stop stop-color="#FFFFFF" offset="49.4650193%"></stop>
              <stop stop-color="#FF3D3D" stop-opacity="0.3" offset="100%"></stop>
          </linearGradient>
          <linearGradient x1="17.0873898%" y1="7.60510177%" x2="17.0873898%" y2="92.959382%" id="linearGradient-2">
              <stop stop-color="#FF3D3D" stop-opacity="0.3" offset="0%"></stop>
              <stop stop-color="#FF3D3D" offset="50.4247678%"></stop>
              <stop stop-color="#FF3D3D" stop-opacity="0.3" offset="99.9181799%"></stop>
          </linearGradient>
          <linearGradient x1="0%" y1="50%" x2="98.6846458%" y2="50%" id="linearGradient-3">
              <stop stop-color="#FF3D3D" stop-opacity="0.45" offset="0%"></stop>
              <stop stop-color="#FF3D3D" stop-opacity="0.08" offset="100%"></stop>
          </linearGradient>
          <polygon id="path-4" points="-1.77635684e-13 4.26325641e-13 225 1.27897692e-13 240 15 240 64 -1.77635684e-13 64"></polygon>
          <filter x="-1.7%" y="-6.2%" width="103.3%" height="112.5%" filterUnits="objectBoundingBox" id="filter-5">
              <feGaussianBlur stdDeviation="4" in="SourceAlpha" result="shadowBlurInner1"></feGaussianBlur>
              <feOffset dx="0" dy="0" in="shadowBlurInner1" result="shadowOffsetInner1"></feOffset>
              <feComposite in="shadowOffsetInner1" in2="SourceAlpha" operator="arithmetic" k2="-1" k3="1" result="shadowInnerInner1"></feComposite>
              <feColorMatrix values="0 0 0 0 1   0 0 0 0 0.239215686   0 0 0 0 0.239215686  0 0 0 0.5 0" type="matrix" in="shadowInnerInner1"></feColorMatrix>
          </filter>
      </defs>
      <g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
          <g id="名称" transform="translate(0.000000, 63.000000)">
              <g id="地标" transform="translate(88.000000, 136.000000)">
                  <path d="M11.7067923,21.2910903 C17.2046917,22.984184 24.2328389,24 31.8915254,24 L31.8915254,24 M46.422388,22.6848552 C56.72963,20.6962495 63.7830508,16.6580657 63.7830508,12 M47.4842337,1.52966612 C42.8740658,0.555526073 37.5552092,0 31.8915254,0 M14.6230742,1.90967296 C5.82483717,4.04592214 0,7.7670065 0,12" id="形状" stroke="#FF3D3D" stroke-width="2" opacity="0.8"></path>
                  <path d="M18.0437956,5.32973697 C12.6133235,6.86503105 9.11186441,9.28173188 9.11186441,12 M16.5952832,18.2246235 C20.6383293,19.5764095 26.0041004,20.4 31.8915254,20.4 L31.8915254,20.4 M46.164223,18.5471511 C51.3517104,17.0074796 54.6711864,14.6466867 54.6711864,12 M43.8364767,4.8460963 C40.3635637,4.05592087 36.2719324,3.6 31.8915254,3.6" id="形状" stroke="#FF3D3D" stroke-width="2" opacity="0.5"></path>
                  <ellipse id="椭圆形" fill="#FF3D3D" cx="31.240678" cy="12" rx="14.3186441" ry="4.8"></ellipse>
              </g>
              <g id="箭头" transform="translate(100.000000, 80.000000)">
                  <g id="编组-7" transform="translate(0.000000, -0.000000)">
                      <polygon id="三角形" fill="#FF3D3D" opacity="0.5" transform="translate(19.666667, 18.052632) scale(1, -1) translate(-19.666667, -18.052632) " points="19.6666667 0 39.3333333 36.1052632 19.6666667 27.2631579 7.99360578e-15 36.1052632"></polygon>
                      <path d="M19.6666667,0.731691304 L38.5286958,35.3597519 L19.6666667,26.8794106 L0.804637521,35.3597519 L19.6666667,0.731691304 Z" id="三角形" stroke="#FF3D3D" stroke-width="0.7" transform="translate(19.666667, 18.052632) scale(1, -1) translate(-19.666667, -18.052632) "></path>
                      <polyline id="FFAF3D" stroke="url(#linearGradient-1)" stroke-width="0.7" transform="translate(19.715833, 26.441759) scale(1, -1) translate(-19.715833, -26.441759) " points="6.13916547 39.7894737 19.6666667 13.0940446 33.2924998 39.7894737"></polyline>
                      <line x1="19.6666667" y1="35.0532205" x2="19.6666667" y2="8.84210526" id="路径-15" stroke="url(#linearGradient-2)" stroke-width="0.7"></line>
                  </g>
              </g>
              <g id="文本框">
                  <g id="文本">
                      <g id="矩形" fill-rule="nonzero">
                          <use fill-opacity="0.85" fill="#151A20" xlink:href="#path-4"></use>
                          <use fill="url(#linearGradient-3)" xlink:href="#path-4"></use>
                          <use fill="black" fill-opacity="1" filter="url(#filter-5)" xlink:href="#path-4"></use>
                          <path stroke="#FF3D3D" stroke-width="1" d="M224.792893,0.5 L239.5,15.2071068 L239.5,63.5 L0.5,63.5 L0.5,0.5 L224.792893,0.5 Z" stroke-linejoin="square"></path>
                      </g>
                      <polygon id="路径-3备份-9" fill="#FF3D3D" points="228 -5.67879077e-14 240 12 240 -5.67879077e-14"></polygon>
                  </g>
                  <g id="文本" transform="translate(16.000000, 8.000000)" fill="#FFFFFF">
                      <text id="${name}" font-family="PingFangSC-Semibold, PingFang SC" font-size="${fontSize}" font-weight="500">
                          <tspan x="0" y="17">${name}</tspan>
                      </text>
                  </g>
              </g>
          </g>
      </g>
  </svg>`;
}

function getGreenImgStr(name, fontSize) {
  return `<?xml version="1.0" encoding="UTF-8"?>
  <svg width="240px" height="224px" viewBox="0 0 240 224" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <title>标记</title>
      <defs>
          <linearGradient x1="100%" y1="98.1720976%" x2="0%" y2="98.3278508%" id="linearGradient-1">
              <stop stop-color="#3DFBFF" stop-opacity="0.3" offset="0%"></stop>
              <stop stop-color="#FFFFFF" offset="49.4650193%"></stop>
              <stop stop-color="#3DFBFF" stop-opacity="0.3" offset="100%"></stop>
          </linearGradient>
          <linearGradient x1="17.0873898%" y1="7.60510177%" x2="17.0873898%" y2="93.1692362%" id="linearGradient-2">
              <stop stop-color="#3DFBFF" stop-opacity="0.297585227" offset="0%"></stop>
              <stop stop-color="#3DFBFF" offset="50.4247678%"></stop>
              <stop stop-color="#3DFBFF" stop-opacity="0.3" offset="100%"></stop>
          </linearGradient>
          <linearGradient x1="0%" y1="50%" x2="98.6846458%" y2="50%" id="linearGradient-3">
              <stop stop-color="#3DFBFF" stop-opacity="0.45" offset="0%"></stop>
              <stop stop-color="#3DFBFF" stop-opacity="0.08" offset="100%"></stop>
          </linearGradient>
          <polygon id="path-4" points="-1.77635684e-13 4.26325641e-13 225 1.27897692e-13 240 15 240 64 -1.77635684e-13 64"></polygon>
          <filter x="-1.7%" y="-6.2%" width="103.3%" height="112.5%" filterUnits="objectBoundingBox" id="filter-5">
              <feGaussianBlur stdDeviation="4" in="SourceAlpha" result="shadowBlurInner1"></feGaussianBlur>
              <feOffset dx="0" dy="0" in="shadowBlurInner1" result="shadowOffsetInner1"></feOffset>
              <feComposite in="shadowOffsetInner1" in2="SourceAlpha" operator="arithmetic" k2="-1" k3="1" result="shadowInnerInner1"></feComposite>
              <feColorMatrix values="0 0 0 0 0.239215686   0 0 0 0 0.984313725   0 0 0 0 1  0 0 0 0.5 0" type="matrix" in="shadowInnerInner1"></feColorMatrix>
          </filter>
      </defs>
      <g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
          <g id="名称" transform="translate(0.000000, 63.000000)">
              <g id="地标" transform="translate(88.000000, 136.000000)">
                  <path d="M11.7067923,21.2910903 C17.2046917,22.984184 24.2328389,24 31.8915254,24 L31.8915254,24 M46.422388,22.6848552 C56.72963,20.6962495 63.7830508,16.6580657 63.7830508,12 M47.4842337,1.52966612 C42.8740658,0.555526073 37.5552092,0 31.8915254,0 M14.6230742,1.90967296 C5.82483717,4.04592214 0,7.7670065 0,12" id="形状" stroke="#3DFBFF" stroke-width="2" opacity="0.8"></path>
                  <path d="M18.0437956,5.32973697 C12.6133235,6.86503105 9.11186441,9.28173188 9.11186441,12 M16.5952832,18.2246235 C20.6383293,19.5764095 26.0041004,20.4 31.8915254,20.4 L31.8915254,20.4 M46.164223,18.5471511 C51.3517104,17.0074796 54.6711864,14.6466867 54.6711864,12 M43.8364767,4.8460963 C40.3635637,4.05592087 36.2719324,3.6 31.8915254,3.6" id="形状" stroke="#3DFBFF" stroke-width="2" opacity="0.5"></path>
                  <ellipse id="椭圆形" fill="#3DFBFF" cx="31.240678" cy="12" rx="14.3186441" ry="4.8"></ellipse>
              </g>
              <g id="箭头" transform="translate(100.000000, 80.000000)">
                  <g id="编组-7" transform="translate(0.000000, -0.000000)">
                      <polygon id="三角形" fill="#3DFBFF" opacity="0.5" transform="translate(19.666667, 18.052632) scale(1, -1) translate(-19.666667, -18.052632) " points="19.6666667 0 39.3333333 36.1052632 19.6666667 27.2631579 7.99360578e-15 36.1052632"></polygon>
                      <path d="M19.6666667,0.731691304 L38.5286958,35.3597519 L19.6666667,26.8794106 L0.804637521,35.3597519 L19.6666667,0.731691304 Z" id="三角形" stroke="#3DFBFF" stroke-width="0.7" transform="translate(19.666667, 18.052632) scale(1, -1) translate(-19.666667, -18.052632) "></path>
                      <polyline id="路径" stroke="url(#linearGradient-1)" stroke-width="0.7" transform="translate(19.715833, 26.441759) scale(1, -1) translate(-19.715833, -26.441759) " points="6.13916547 39.7894737 19.6666667 13.0940446 33.2924998 39.7894737"></polyline>
                      <line x1="19.6666667" y1="35.0532205" x2="19.6666667" y2="8.84210526" id="路径-15" stroke="url(#linearGradient-2)" stroke-width="0.7"></line>
                  </g>
              </g>
              <g id="文本框">
                  <g id="文本">
                      <g id="矩形" fill-rule="nonzero">
                          <use fill-opacity="0.85" fill="#151A20" xlink:href="#path-4"></use>
                          <use fill="url(#linearGradient-3)" xlink:href="#path-4"></use>
                          <use fill="black" fill-opacity="1" filter="url(#filter-5)" xlink:href="#path-4"></use>
                          <path stroke="#3DFBFF" stroke-width="1" d="M224.792893,0.5 L239.5,15.2071068 L239.5,63.5 L0.5,63.5 L0.5,0.5 L224.792893,0.5 Z" stroke-linejoin="square"></path>
                      </g>
                      <polygon id="路径-3备份-9" fill="#3DFBFF" points="228 -5.67879077e-14 240 12 240 -5.67879077e-14"></polygon>
                  </g>
                  <g id="文本" transform="translate(16.000000, 8.000000)" fill="#FFFFFF">
                      <text id="${name}" font-family="PingFangSC-Semibold, PingFang SC" font-size="${fontSize}" font-weight="500">
                          <tspan x="0" y="17">${name}</tspan>
                      </text>

                  </g>
              </g>
          </g>
      </g>
  </svg>`;
}

function getYellowImgStr(name, fontSize) {
  return `<?xml version="1.0" encoding="UTF-8"?>
  <svg width="240px" height="224px" viewBox="0 0 240 224" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <title>标记</title>
      <defs>
          <linearGradient x1="100%" y1="98.1720976%" x2="0%" y2="98.3278508%" id="linearGradient-1">
              <stop stop-color="#FFAF3D" stop-opacity="0.3" offset="0%"></stop>
              <stop stop-color="#FFFFFF" offset="49.4650193%"></stop>
              <stop stop-color="#FFAF3D" stop-opacity="0.3" offset="100%"></stop>
          </linearGradient>
          <linearGradient x1="17.0873898%" y1="7.60510177%" x2="17.0873898%" y2="93.1692362%" id="linearGradient-2">
              <stop stop-color="#FFAF3D" stop-opacity="0.3" offset="0%"></stop>
              <stop stop-color="#FFAF3D" offset="50.4247678%"></stop>
              <stop stop-color="#FFAF3D" stop-opacity="0.3" offset="99.9181799%"></stop>
          </linearGradient>
          <linearGradient x1="0%" y1="50%" x2="98.6846458%" y2="50%" id="linearGradient-3">
              <stop stop-color="#FFAF3D" stop-opacity="0.45" offset="0%"></stop>
              <stop stop-color="#FFAF3D" stop-opacity="0.08" offset="100%"></stop>
          </linearGradient>
          <polygon id="path-4" points="-1.77635684e-13 4.26325641e-13 225 1.27897692e-13 240 15 240 64 -1.77635684e-13 64"></polygon>
          <filter x="-1.7%" y="-6.2%" width="103.3%" height="112.5%" filterUnits="objectBoundingBox" id="filter-5">
              <feGaussianBlur stdDeviation="4" in="SourceAlpha" result="shadowBlurInner1"></feGaussianBlur>
              <feOffset dx="0" dy="0" in="shadowBlurInner1" result="shadowOffsetInner1"></feOffset>
              <feComposite in="shadowOffsetInner1" in2="SourceAlpha" operator="arithmetic" k2="-1" k3="1" result="shadowInnerInner1"></feComposite>
              <feColorMatrix values="0 0 0 0 1   0 0 0 0 0.68627451   0 0 0 0 0.239215686  0 0 0 0.5 0" type="matrix" in="shadowInnerInner1"></feColorMatrix>
          </filter>
      </defs>
      <g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
          <g id="名称" transform="translate(0.000000, 63.000000)">
              <g id="地标" transform="translate(88.000000, 136.000000)">
                  <path d="M11.7067923,21.2910903 C17.2046917,22.984184 24.2328389,24 31.8915254,24 L31.8915254,24 M46.422388,22.6848552 C56.72963,20.6962495 63.7830508,16.6580657 63.7830508,12 M47.4842337,1.52966612 C42.8740658,0.555526073 37.5552092,0 31.8915254,0 M14.6230742,1.90967296 C5.82483717,4.04592214 0,7.7670065 0,12" id="形状" stroke="#FFAF3D" stroke-width="2" opacity="0.8"></path>
                  <path d="M18.0437956,5.32973697 C12.6133235,6.86503105 9.11186441,9.28173188 9.11186441,12 M16.5952832,18.2246235 C20.6383293,19.5764095 26.0041004,20.4 31.8915254,20.4 L31.8915254,20.4 M46.164223,18.5471511 C51.3517104,17.0074796 54.6711864,14.6466867 54.6711864,12 M43.8364767,4.8460963 C40.3635637,4.05592087 36.2719324,3.6 31.8915254,3.6" id="形状" stroke="#FFAF3D" stroke-width="2" opacity="0.5"></path>
                  <ellipse id="椭圆形" fill="#FFAF3D" cx="31.240678" cy="12" rx="14.3186441" ry="4.8"></ellipse>
              </g>
              <g id="箭头" transform="translate(100.000000, 80.000000)">
                  <g id="编组-7" transform="translate(0.000000, -0.000000)">
                      <polygon id="三角形" fill="#FFAF3D" opacity="0.5" transform="translate(19.666667, 18.052632) scale(1, -1) translate(-19.666667, -18.052632) " points="19.6666667 0 39.3333333 36.1052632 19.6666667 27.2631579 7.99360578e-15 36.1052632"></polygon>
                      <path d="M19.6666667,0.731691304 L38.5286958,35.3597519 L19.6666667,26.8794106 L0.804637521,35.3597519 L19.6666667,0.731691304 Z" id="三角形" stroke="#FFAF3D" stroke-width="0.7" transform="translate(19.666667, 18.052632) scale(1, -1) translate(-19.666667, -18.052632) "></path>
                      <polyline id="FFAF3D" stroke="url(#linearGradient-1)" stroke-width="0.7" transform="translate(19.715833, 26.441759) scale(1, -1) translate(-19.715833, -26.441759) " points="6.13916547 39.7894737 19.6666667 13.0940446 33.2924998 39.7894737"></polyline>
                      <line x1="19.6666667" y1="35.0532205" x2="19.6666667" y2="8.84210526" id="路径-15" stroke="url(#linearGradient-2)" stroke-width="0.7"></line>
                  </g>
              </g>
              <g id="文本框">
                  <g id="文本">
                      <g id="矩形" fill-rule="nonzero">
                          <use fill-opacity="0.85" fill="#151A20" xlink:href="#path-4"></use>
                          <use fill="url(#linearGradient-3)" xlink:href="#path-4"></use>
                          <use fill="black" fill-opacity="1" filter="url(#filter-5)" xlink:href="#path-4"></use>
                          <path stroke="#FFAF3D" stroke-width="1" d="M224.792893,0.5 L239.5,15.2071068 L239.5,63.5 L0.5,63.5 L0.5,0.5 L224.792893,0.5 Z" stroke-linejoin="square"></path>
                      </g>
                      <polygon id="路径-3备份-9" fill="#FFAF3D" points="228 -5.67879077e-14 240 12 240 -5.67879077e-14"></polygon>
                  </g>
                  <g id="文本" transform="translate(16.000000, 8.000000)" fill="#FFFFFF">
                      <text id="${name}" font-family="PingFangSC-Semibold, PingFang SC" font-size="${fontSize}" font-weight="500">
                          <tspan x="0" y="17">${name}</tspan>
                      </text>

                  </g>
              </g>
          </g>
      </g>
  </svg>`;
}
